package {

	/**
	 * QRCode library @author Kazuhiko Arase 
	 * http://www.d-project.com/
	 * http://www.d-project.com/qrcode/index.html
	 * QRCode library @copyright Kazuhiko Arase, not covered by the implementation's MIT license.
	 * 
	 * Implementation by 
	 *		Marcos Weskamp 
	 * 		marcos@marumushi.com 
	 * 		marumushi.com
	 * 
	 * Celisa Library is @copyright marcos@marumushi.com
	 * */
    import celisa.core.Application;
    import celisa.utils.DateUtil;
    
    import com.d_project.qrcode.view.QRCode;
    
    import flash.events.Event;
    import flash.events.TimerEvent;
    import flash.utils.Timer;

	[SWF (frameRate="61", backgroundColor="#FFFFFF", width="800",height="800")]
    public class QRCodeClock extends Application {

		private var timer		:Timer 				= new Timer(50);
		private var qrcode		:QRCode 			= new QRCode(600);
		private var lastTime	:String;
		
        public function QRCodeClock() {
        	addChild(qrcode);
        	stage.addEventListener(Event.RESIZE,onResize);
			timer.addEventListener(TimerEvent.TIMER,onTimerTick);
			timer.start();
			onTimerTick();
			onResize();
        }
        
        private function onResize(evt:*=null):void{
            qrcode.x = int((stage.stageWidth/2)-(qrcode.width/2));
        	qrcode.y = int((stage.stageHeight/2)-(qrcode.height/2));	
        }
        
        private function onTimerTick(evt:*=null):void{
        	var time:String = DateUtil.getFormatedDate(new Date(),'hh:mm:ss');
        	if(lastTime!=time){
        		qrcode.text = 'Current time is: '+time+'! Hammer time!';
          		lastTime = time;
        	}
        }
    }
}

